package com.xuelang.pipeline.artifact.app.harborv2;

import com.xuelang.pipeline.artifact.app.harborv2.config.HarborV2FeignConfig;
import com.xuelang.pipeline.artifact.app.harborv2.fallback.MemberServiceFallbackFactory;
import com.xuelang.pipeline.artifact.app.harborv2.request.CreateMemberRequest;
import com.xuelang.pipeline.artifact.app.harborv2.request.ListMemberQuery;
import com.xuelang.pipeline.artifact.app.harborv2.response.SearchUserResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

/**
 * 封装Docker v2.11.0-70255684以上项目成员相关接口-对应member
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@FeignClient(
        name = "member-service",
        url = "${feign.rpc.harborV2Service}",
        configuration = HarborV2FeignConfig.class,
        fallbackFactory = MemberServiceFallbackFactory.class)
public interface MemberService {

    /**
     * 得到项目成员列表
     *
     * @param projectNameOrId
     * @param query
     * @return
     */
    @GetMapping(value = "/projects/{project_name_or_id}/members", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> listProjectMember(@PathVariable("project_name_or_id") String projectNameOrId, @ModelAttribute ListMemberQuery query);

    /**
     * 创建项目成员
     *
     * @param projectNameOrId
     * @param request
     * @return
     */
    @PostMapping(value = "/projects/{project_name_or_id}/members", produces = "application/json;charset=utf-8")
    ApiResponseXO<SearchUserResponse> createProjectMember(@PathVariable("project_name_or_id") String projectNameOrId, @RequestBody @Valid CreateMemberRequest request);

    /**
     * 删除项目成员
     *
     * @param projectNameOrId
     * @param memberId
     * @return
     */
    @DeleteMapping(value = "/projects/{project_name_or_id}/members/{mid}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteProjectMember(@PathVariable("project_name_or_id") String projectNameOrId, @PathVariable("mid") String memberId);



}
